async function render() {
  const result = await axios({
    url: "/dashboard",
  });
  const dataItem = result.data.data.overview; // 主页内容
  document.querySelector("[name=salary]").innerText = dataItem.salary; // 平均薪资
  document.querySelector("[name=group_count]").innerText = dataItem.group_count; // 小组人数
  document.querySelector("[name=student_count]").innerText =
    dataItem.student_count; // 平均班级人数
  document.querySelector("[name=age]").innerText = dataItem.age; // 年龄
  console.log(result);

  //   console.log(data);

  const dataMon = result.data.data.year; // 月份以及平均薪资
  console.log(dataMon);
  trend(dataMon);
  const salarys = result.data.data.salaryData; // 平均薪资
  console.log(salarys);
  salary(salarys);
  const dataName = result.data.data.groupData; // 名字
  getOne(dataName);
}
render();

// 科学走势
function trend(arr2) {
  const month = arr2.map((item) => item.month);
  const salary = arr2.map((item) => item.salary);
  /* console.log(month);
  console.log(salary); */
  const myChart = echarts.init(document.querySelector("#line"));
  // 指定图表的配置项和数据
  const option = {
    xAxis: {
      type: "category",
      data: month,
    },
    yAxis: {
      type: "value",
    },
    series: [
      {
        data: salary,
        type: "line",
        smooth: true,
      },
    ],
  };
  // 使用刚指定的配置项和数据显示图表。
  myChart.setOption(option);
}

// 班级薪资分布
function salary(arr3) {
  /* const label = arr3.map((item) => item.label);
  console.log(label);
  const g_count = arr3.map((item) => item.g_count);
  const b_count = arr3.map((item) => item.b_count);
  console.log(g_count);
  console.log(b_count); */
  const salaryData = arr3.map((item) => {
    return { value: parseInt(item.g_count) + item.b_count, name: item.label };
  });
  // const newsalaryData = JSON.parse(salaryData);
  console.log(salaryData);

  const myChart = echarts.init(document.querySelector("#salary"));
  // 指定图表的配置项和数据
  const option = {
    tooltip: {
      trigger: "item",
    },
    legend: {
      top: "5%",
      left: "center",
    },
    series: [
      {
        name: "Access From",
        type: "pie",
        radius: ["40%", "70%"],
        avoidLabelOverlap: false,
        itemStyle: {
          borderRadius: 10,
          borderColor: "#fff",
          borderWidth: 2,
        },
        label: {
          show: false,
          position: "center",
        },
        emphasis: {
          label: {
            show: true,
            fontSize: 40,
            fontWeight: "bold",
          },
        },
        labelLine: {
          show: false,
        },
        data: salaryData,
      },
    ],
  };
  // 使用刚指定的配置项和数据显示图表。
  myChart.setOption(option);
}

//
function getOne(arr = 1) {
  //   const mon = arr.forEach((element) => console.log(element));
  for (const key in arr) {
    /* console.log(key);
    console.log(arr[key]); */
    const uname = arr[key].map(
      (element) => element.name
      // console.log(element);
    );
    console.log(uname);
  }
  /* const myChart = echarts.init(document.querySelector("#line"));

  // 指定图表的配置项和数据
  const option = {
    xAxis: {
      type: "category",
      data: ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
    },
    yAxis: {
      type: "value",
    },
    series: [
      {
        data: [820, 932, 901, 934, 1290, 1330, 1320],
        type: "line",
        smooth: true,
      },
    ],
  };
  // 使用刚指定的配置项和数据显示图表。
  myChart.setOption(option); */
}
